package com.liao.product.controller;

import com.liao.common.entity.product.BannerEntity;
import com.liao.common.utils.PageUtils;
import com.liao.product.service.BannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


/**
 * 广告轮播图
 *
 * @author liao
 * @email 2858015963@qq.com
 * @date 2025-03-17 20:06:16
 */
@RestController
@RequestMapping("product/banner")
public class BannerController {
    @Autowired
    private BannerService bannerService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public PageUtils<BannerEntity> list(@RequestParam Map<String, Object> params) {
        PageUtils page = bannerService.queryPage(params);

        return page;
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public BannerEntity info(@PathVariable("id") Integer id) {
        BannerEntity banner = bannerService.getById(id);

        return banner;
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public void save(@RequestBody BannerEntity banner) {
        bannerService.save(banner);

    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public void update(@RequestBody BannerEntity banner) {
        bannerService.updateById(banner);

    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public void delete(@RequestBody Integer[] ids) {
        bannerService.removeByIds(Arrays.asList(ids));

    }

    /**
     * 广告区域
     *
     * @return
     */
    @GetMapping("/show")
    public List<BannerEntity> getBannerList(@RequestParam(value = "type", defaultValue = "1") Integer type) {
        return bannerService.getBannerList(type);

    }


}
